﻿using System;
using System.Collections.Generic;

using System.Text;
using System.IO;

namespace Estimate.Common.DataFileFinder
{
    /// <summary>
    /// 指导站点数据文件发现类
    /// </summary>
    public class SiteForeFinder:IDataFileFinder
    {
        public string[] GetFileFromDirectory(DateTime dt, string dirPath)
        {
            if (!checkDateValide(dt))
                return new string[] { };

            List<string> result = new List<string>();

            string[] clk = new string[] { "08", "20" };
            string[] spn = new string[] { "024", "048", "072", "096", "120", "144", "168" };

            string filename;

            foreach (string clock in clk)
            {
                foreach (string span in spn)
                {
                        filename =  "RS" + dt.ToString("MMdd" + clock + "." + span);

                        if (File.Exists(dirPath + filename))
                        {
                            result.Add(dirPath + filename);
                        }
                }
            }
            return result.ToArray();           
        }

        /// <summary>
        /// SiteFore 的源文件夹存储及命名规范，导致拿不到早于1年的数据
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private bool checkDateValide(DateTime dt)
        {
            DateTime now = DateTime.Now;
            DateTime same_day_of_last_year = new DateTime(now.Year - 1, now.Month, now.Day + 2 > 31 ? 31 : now.Day + 2);
            if (dt <= same_day_of_last_year)
                return false;
            return true;
        }


        public string[] GetFileNames(DateTime dt)
        {
            List<string> result = new List<string>();

            string[] clk = new string[] { "08", "20" };
            string[] spn = new string[] { "024", "048", "072", "096", "120", "144", "168" };

            string filename;

            foreach (string clock in clk)
            {
                foreach (string span in spn)
                {
                    filename = "RS" + dt.ToString("MMdd" + clock + "." + span);                   
                    result.Add(filename);                    
                }
            }
            return result.ToArray();          
        }


        public Dictionary<string, string[]> GetFileListFromDirectory(DateTime dt, string dirPath)
        {
            throw new NotImplementedException();
        }
    }
}
